<?php
defined('_JEXEC') or die('Restricted access');
class Tools {

    public static function sendToClient_JSON(array $data) {
        header('Content-type: application/json');
        echo json_encode($data);
    }

    /**
     * @flatten multi-dimensional array
     * @param array $array
     * @return array
     */
    public static function flattenArray(array $array) {
        $ret_array = array();
        foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($array)) as $value) {
            $ret_array[] = $value;
        }
        return $ret_array;
    }

    public static function hasOnlyDigits($toCheck) {
        $digits = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
        $n = (string) $toCheck;
        
        if (strlen($n)<1) {return FALSE;}
        
        $len = strlen($n);

        for ($i = 0; $i < $len; $i++) {
            if (!in_array(substr($n, $i, 1), $digits)) {
                return FALSE;
            }
        }

        return true;
    }

    public static function redirect($redirectTo){
        header('location: '.$redirectTo);
    }
}

?>
